package cn.edu.hpu.jie.services;

import java.util.List;

import cn.edu.hpu.jie.dao.NewsDao;
import cn.edu.hpu.jie.entity.Log;
import cn.edu.hpu.jie.entity.News;
import cn.edu.hpu.jie.entity.NewsSites;
import cn.edu.hpu.jie.util.DateUtil;

public class NewsService {
	private NewsDao dao = new NewsDao();
	
	public int insertNews(NewsSites ns, int loginid) {
		int eventid = dao.insertNews(ns);
		LogService ls = new LogService();
		Log l = new Log();
		l.setDesc("添加了一条新闻");
		l.setEventid(eventid);
		l.setLoginid(loginid);
		l.setTime(ns.getCreatetime());
		return ls.insertLog(l);
	}
	
	public List<News> getAll() {
		return dao.getAllNews();
	}

	public NewsSites getNewsSitesById(int id) {
		return dao.getNewsSitesById(id);
	}

	public int editNews(NewsSites ns, int loginid) {
		dao.editNewsById(ns);
		LogService ls = new LogService();
		Log l = new Log();
		l.setDesc("修改了一条新闻");
		l.setEventid(ns.getId());
		l.setLoginid(loginid);
		l.setTime(DateUtil.getNow());
		return ls.insertLog(l);
	}
}
